/**
 * 热更新
 */

var path = '1.0.1'
var customMainFest = {}

var HotUpdate = () => {
  this.path = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + path)
  this.tempPath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + path+'_temp')
  jsb.fileUtils.removeDirectory(this.tempPath)
  cc.log('清空temp，不清空会导致bug : ' + this.path)

  this.versionCompareHandle = function (versionA, versionB) {
    if(versionA == versionB) return 0
    if(versionA != versionB) return -1
    return 1
  }

  this._am = new jsb.AssetsManager('', this.path, this.versionCompareHandle)
  this._am.setVerifyCallback(function (path, asset) {
    var compressed = asset.compressed;
    var expectedMD5 = asset.md5;
    var relativePath = asset.path;
    var size = asset.size;
    if (compressed) {
      return true;
    } else {
      return true;
    }
  })

  if (cc.sys.os === cc.sys.OS_ANDROID) {
    this._am.setMaxConcurrentTask(2)
  }
}

module.exports = HotUpdate
var proto = HotUpdate.prototype

proto.destroy = () => {
  if (this._updateListener) {
    this._am.setEventCallback(null);
    this._updateListener = null;
  }
}


